package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OrderBean;
import com.project.bean.UserBean;
import com.project.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private IOrderService service;
    @RequestMapping("custom/addOrder")
    private String addOrder(OrderBean order, HttpServletRequest req){
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        //设置用户ID
        order.setUserId(user.getId());

        service.addOrder(order);

        return "ok";
    }
    @RequestMapping("custom/findByUser")
    public IPage<OrderBean> findByUser(HttpServletRequest req,Integer pageNO){
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        return service.findByUser(pageNO, user.getId());
    }
    @RequestMapping("getOrder")
    public OrderBean getOrder(Integer orderId){
        return service.findOrder(orderId);
    }

    @RequestMapping("manager/selectByItems")
    public IPage<OrderBean> selectByItems(Integer pageNO, String status, LocalDate startDate, LocalDate endDate){
        return service.selectByItems(pageNO, status, startDate, endDate);
    }
    @RequestMapping("manager/sendOrder")
    public String sendOrder(Integer orderId){
        service.sendOrder(orderId);
        return "ok";
    }
    @RequestMapping("send/findSending")
    public List<OrderBean> findSending(){
        return service.findSending();
    }
    @RequestMapping("send/changeStatus")
    public String changeStatus(Integer orderId){
        service.changeStatus(orderId);
        return "ok";
    }

}
